package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bizsys.mapper.RealNameAuthMapper;
import com.ruoyi.bizsys.domain.RealNameAuth;
import com.ruoyi.bizsys.service.IRealNameAuthService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 实名认证Service业务层处理
 *
 * @author african-loan
 * @date 2021-12-30
 */
@Service
public class RealNameAuthServiceImpl extends ServiceImpl<RealNameAuthMapper, RealNameAuth> implements IRealNameAuthService {

    @Autowired
    private RealNameAuthMapper realNameAuthMapper;

    /**
     * 查询实名认证
     *
     * @param id 实名认证ID
     * @return 实名认证
     */
    @Override
    public RealNameAuth selectRealNameAuthById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询实名认证列表
     *
     * @param realNameAuth 实名认证
     * @return 实名认证
     */
    @Override
    public List<RealNameAuth> selectRealNameAuthList(RealNameAuth realNameAuth) {
        return this.list(new QueryWrapper<>(realNameAuth).last("order by id desc"));
    }

    /**
     * 新增实名认证
     *
     * @param realNameAuth 实名认证
     * @return 结果
     */
    @Override
    public int insertRealNameAuth(RealNameAuth realNameAuth) {
        realNameAuth.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(realNameAuth);
    }

    /**
     * 修改实名认证
     *
     * @param realNameAuth 实名认证
     * @return 结果
     */
    @Override
    public int updateRealNameAuth(RealNameAuth realNameAuth) {
        realNameAuth.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(realNameAuth);
    }

    /**
     * 批量删除实名认证
     *
     * @param ids 需要删除的实名认证ID
     * @return 结果
     */
    @Override
    public int deleteRealNameAuthByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除实名认证信息
     *
     * @param id 实名认证ID
     * @return 结果
     */
    @Override
    public int deleteRealNameAuthById(Long id) {
        return baseMapper.deleteById(id);
    }


    @Override
    public RealNameAuth selectRealNameAuthByCustNo(String custNo) {
        return realNameAuthMapper.selectRealNameAuthByCustNo(custNo);
    }

    @Override
    public RealNameAuth getOneByUserId(String userId) {
        return getOne(new LambdaQueryWrapper<RealNameAuth>().eq(RealNameAuth::getUserId, userId).eq(RealNameAuth::getState,1));
    }

    @Override
    public RealNameAuth getOneByCustNo(String custNo) {
        QueryWrapper<RealNameAuth> realNameAuthQueryWrapper = new QueryWrapper<>();
        realNameAuthQueryWrapper.eq("cust_no", custNo);
        return getOne(realNameAuthQueryWrapper);
    }

    @Override
    public String selectRealNameBvnTotal(String custNo) {
        return realNameAuthMapper.selectRealNameBvnTotal(custNo);
    }

    @Override
    public int selectRealNameBvnCnt(String custNo) {
        int i = realNameAuthMapper.selectRealNameBvnCnt(custNo);
        if (i > 0) {
            return realNameAuthMapper.selectRealNameBvnCnt(custNo);
        }
        return -1;
    }

    @Override
    public String selectFirstName(String custNo) {
        return realNameAuthMapper.selectFirstName(custNo);
    }


}
